<!-- wyf 2022-1-20 -->
<template>
  <a-input
    :id="id"
    :ref="inputRef"
    v-model:value="iptValue"
    class="z-input"
    :disabled="disabled"
    :allow-clear="allowClear"
    :bordered="bordered"
    :default-value="defaultValue"
    :addon-after="addonAfter"
    :addon-before="addonBefore"
    :maxlength="maxlength"
    :prefix="prefix"
    :suffix="suffix"
    :show-count="showCount"
    :type="type"
    :size="size"
    :placeholder="placeholder"
  >
    <template v-if="$slots.prefix" #prefix>
      <slot name="prefix" />
    </template>
    <template v-if="$slots.suffix" #suffix>
      <slot name="suffix" />
    </template>
    <template v-if="$slots.addonAfter" #addonAfter>
      <slot name="addonAfter" />
    </template>
    <template v-if="$slots.addonBefore" #addonBefore>
      <slot name="addonBefore" />
    </template>
    <slot />
  </a-input>
</template>

<script>
import { defineComponent, computed } from 'vue'
import { Input } from 'ant-design-vue'
export default defineComponent({
  name: 'ZInput',
  components: {
    AInput: Input
  },
  props: {
    inputRef: {
      type: String,
      default: 'inputRef'
    },
    value: {
      type: [String, Number],
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    allowClear: {
      type: Boolean,
      default: false
    },
    bordered: {
      type: Boolean,
      default: true
    },
    defaultValue: {
      type: String,
      default: undefined
    },
    addonAfter: {
      type: String,
      default: undefined
    },
    addonBefore: {
      type: String,
      default: undefined
    },
    id: {
      type: String,
      default: undefined
    },
    maxlength: {
      type: Number,
      default: undefined
    },
    prefix: {
      type: String,
      default: undefined
    },
    showCount: {
      type: Boolean,
      default: false
    },
    size: {
      type: String,
      default: 'default'
    },
    suffix: {
      type: String,
      default: undefined
    },
    type: {
      type: String,
      default: 'text'
    },
    placeholder: {
      type: String,
      default: undefined
    }
  },
  setup(props, _ref) {
    const iptValue = computed({
      get() {
        return props.value?.toString()
      },
      set(val) {
        _ref.emit('update:value', val)
      }
    })
    return {
      iptValue
    }
  }
})
</script>
